package sg.edu.ntu.sci.blackboard;

import java.io.IOException;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import sg.edu.ntu.sci.blackboard.agilix.AgilixManifestReader;
import sg.edu.ntu.sci.blackboard.agilix.LODocumentResolver;
import sg.edu.ntu.sci.blackboard.agilix.model.Course;
import sg.edu.ntu.sci.blackboard.agilix.model.CourseDocument;
import sg.edu.ntu.sci.blackboard.agilix.model.Doc;
import sg.edu.ntu.sci.blackboard.agilix.model.Folder;

/**
 *
 * @author ngocgiang
 */
public class Main {
    
    private static Log log = LogFactory.getLog(Main.class);

    public static void main(String[] args) {
        try {
            AgilixManifestReader reader = new AgilixManifestReader();
            LODocumentResolver docResolver = new LODocumentResolver();

            List<Course> courses = reader.parseManifest();
            Course course = courses.get(0);
            List<Folder> folders = course.getFolders();
            for (Folder folder : folders) {
                if (folder instanceof CourseDocument) {
                    CourseDocument courseDocument = (CourseDocument) folder;
                    List<Doc> documents = courseDocument.getDocuments();
                    for (Doc document : documents) {
                        String url = docResolver.resolve(document);
                        System.out.println(url);
                    }
                    break;
                }
            }
        } catch (IOException e) {
            log.error("Error in reading file", e);
        }
    }

}
